package com.qf.controller;

import com.qf.pojo.Type;
import com.qf.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController("/type")
public class TypeController {
    @Autowired
    TypeService typeService;

    @RequestMapping("/findTypeAll")
    public List<Type> findAll(){
        return typeService.findAll();
    }

    @RequestMapping("/findTypeById")
    public Type findById(@RequestBody Map map){
        Integer id=(Integer)map.get("id");
        return typeService.findById(id);
    }
    @RequestMapping("/findTypeByLanguage")
    public List<Type> findByLanguage(@RequestBody Map map){
        String l=(String) map.get("language");
        return typeService.findByLanguage(l);
    }


    @RequestMapping("/findTypeByStyle")
    public List<Type> findByStyle(@RequestBody Map map){
        String l=(String) map.get("style");
        return typeService.findByStyle(l);
    }
    @RequestMapping("/findTypeByChangJing")
    public List<Type> findByChangJing(@RequestBody Map map){
        String l=(String) map.get("changjing");
        return typeService.findByChangJing(l);
    }
    @RequestMapping("/findTypeByQingGan")
    public List<Type> findByQingGan(@RequestBody Map map){
        String l=(String) map.get("qinggan");
        return typeService.findByQingGan(l);
    }
    @RequestMapping("/findTypeByZhuTi")
    public List<Type> findByZhuTi(@RequestBody Map map){
        String l=(String) map.get("zhuti");
        return typeService.findByZhuTi(l);
    }

    @RequestMapping("/addAndUpdateType")
    public String addAndUpdate(Type type){
        Type type1 = typeService.addAndUpdate(type);
        if (type1!=null){
            return "success";
        }else{
            return "fail";
        }
    }
    @RequestMapping("/deleteByTid")
    public void delete(@RequestBody Map map){
        Integer id=(Integer)map.get("id");
        typeService.delete(id);
    }
}
